package com.settlement.system.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

@Data
public class SysOrderDetailVo {
    private String id;
    private String yzNo;
    /**
     * OMS单号
     */
    private String omsNo;


    /**
     * 发退货时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime opTime;


    /**
     * 下单时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime buyTime;


    /**
     * 原始主订单号
     */
    private String sourceMainNo;


    /**
     * 原始子订单号
     */
    private String sourceSubNo;


    /**
     * 店铺ID
     */
    private Long storeId;
    private String storeName;


    /**
     * PO单号
     */
    private String poNo;


    /**
     * 商品单价
     */
    private BigDecimal price;


    /**
     * 发货数量
     */
    private Integer qty;


    /**
     * 发货金额
     */
    private BigDecimal sendAmount;


    /**
     * 退货数量
     */
    private Integer returnQty = 0;


    /**
     * 退货金额
     */
    private BigDecimal returnAmount;


    /**
     * 品牌
     */
    private String brand;


    /**
     * SKU
     */
    private String sku;


    /**
     * 商品名称
     */
    private String productName;


    /**
     * 订单状态
     */
    private String orderStatus;

    /**
     * 订单类型
     */
    private Integer orderType;
    private String orderTypeName;


    // 明细
    private String member;
    private String distributeStatus;
    private String payType;
    private String payStatus;
    private String sendWarehouse;
    private String receiver;
    private String receiverPhone;
    private String receiverMobile;
    private String receiverAddress;
    private String province;
    private String city;
    private String area;
    private String buyName;
    private String distributeType;
    private String depositPayTime;
    private String inTime;
    private String confirmTime;
    private String noticeTime;
    private String distributeTime;
    private String outTime;
    private String suspend;
    private String customerMessage;
    private String sellerRemark;
    private String orderRemark;
    private String preDistributeQty;
    private String spec;
    private String preSendTime;
    private String deliveryNo;
    private String goodsAmount;
    private String goodsTag;
    private String goodsName;
    private String goodsId;
    private String wmsOrderNo;
    private String actPayAmount;
    private String preferInfo;
    private String wmsPushNo;

    public static boolean isDate(String field){
        return "opTime,buyTime".contains(field);
    }

    public static boolean isDecimal(String field){
        return "price,sendAmount,returnAmount".contains(field);
    }

    public static boolean isInteger(String field){
        return "qty".contains(field);
    }

    private static boolean compareDate(LocalDateTime date1, LocalDateTime date2) {
        if (date1 == null && date2 == null) {
            return true;
        }
        if (date1 != null && date2 == null) {
            return false;
        }
        return date1 != null && date1.equals(date2);
    }

    private static boolean compareBigDecimal(BigDecimal value1, BigDecimal value2) {
        if (value1 == null && value2 == null) {
            return true;
        }
        if (Objects.isNull(value2)) {
            value2 = BigDecimal.ZERO;
        }
        return value1 != null && value1.compareTo(value2) == 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        SysOrderDetailVo vo = (SysOrderDetailVo) o;
        return Objects.equals(yzNo, vo.yzNo) && Objects.equals(omsNo, vo.omsNo) && compareDate(opTime, vo.opTime) && compareDate(buyTime, vo.buyTime) && Objects.equals(sourceMainNo, vo.sourceMainNo) && Objects.equals(sourceSubNo, vo.sourceSubNo) && Objects.equals(storeId, vo.storeId) && Objects.equals(poNo, vo.poNo) && compareBigDecimal(price, vo.price) && Objects.equals(qty, vo.qty) && compareBigDecimal(sendAmount, vo.sendAmount) && Objects.equals(returnQty, vo.returnQty) && compareBigDecimal(returnAmount, vo.returnAmount) && Objects.equals(brand, vo.brand) && Objects.equals(sku, vo.sku) && Objects.equals(productName, vo.productName) && Objects.equals(orderStatus, vo.orderStatus) && Objects.equals(orderType, vo.orderType) && Objects.equals(member, vo.member) && Objects.equals(distributeStatus, vo.distributeStatus) && Objects.equals(payType, vo.payType) && Objects.equals(payStatus, vo.payStatus) && Objects.equals(sendWarehouse, vo.sendWarehouse) && Objects.equals(receiver, vo.receiver) && Objects.equals(receiverPhone, vo.receiverPhone) && Objects.equals(receiverMobile, vo.receiverMobile) && Objects.equals(receiverAddress, vo.receiverAddress) && Objects.equals(province, vo.province) && Objects.equals(city, vo.city) && Objects.equals(area, vo.area) && Objects.equals(buyName, vo.buyName) && Objects.equals(distributeType, vo.distributeType) && Objects.equals(depositPayTime, vo.depositPayTime) && Objects.equals(inTime, vo.inTime) && Objects.equals(confirmTime, vo.confirmTime) && Objects.equals(noticeTime, vo.noticeTime) && Objects.equals(distributeTime, vo.distributeTime) && Objects.equals(outTime, vo.outTime) && Objects.equals(suspend, vo.suspend) && Objects.equals(customerMessage, vo.customerMessage) && Objects.equals(sellerRemark, vo.sellerRemark) && Objects.equals(orderRemark, vo.orderRemark) && Objects.equals(preDistributeQty, vo.preDistributeQty) && Objects.equals(spec, vo.spec) && Objects.equals(preSendTime, vo.preSendTime) && Objects.equals(deliveryNo, vo.deliveryNo) && Objects.equals(goodsAmount, vo.goodsAmount) && Objects.equals(goodsTag, vo.goodsTag) && Objects.equals(goodsName, vo.goodsName) && Objects.equals(goodsId, vo.goodsId) && Objects.equals(wmsOrderNo, vo.wmsOrderNo) && Objects.equals(actPayAmount, vo.actPayAmount) && Objects.equals(preferInfo, vo.preferInfo) && Objects.equals(wmsPushNo, vo.wmsPushNo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(yzNo, omsNo, opTime, buyTime, sourceMainNo, sourceSubNo, storeId, poNo, price, qty, sendAmount, returnQty, returnAmount, brand, sku, productName, orderStatus, orderType, member, distributeStatus, payType, payStatus, sendWarehouse, receiver, receiverPhone, receiverMobile, receiverAddress, province, city, area, buyName, distributeType, depositPayTime, inTime, confirmTime, noticeTime, distributeTime, outTime, suspend, customerMessage, sellerRemark, orderRemark, preDistributeQty, spec, preSendTime, deliveryNo, goodsAmount, goodsTag, goodsName, goodsId, wmsOrderNo, actPayAmount, preferInfo, wmsPushNo);
    }
}
